package com.bw.lib_http

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)//四大组件中单例
object HttpHiltModule {

    /**
     * 提供OkHttpClient单例
     */

    @HttpClientAnnotation
    @Provides
    @Singleton
    fun providerOkHttpClient():OkHttpClient{
        return OkHttpClientManager.createOkHttpClient()
    }

    /**
     * 提供OkHttpsClient单例
     */
    @HttpClientAnnotation
    @Provides
    @Singleton
    fun providerOkHttpsClient():OkHttpClient{
        return OkHttpClientManager.createOkHttpsClient()
    }

    /**
     * 提供HttpRetrofit单例
     */
    @HttpRetrofitAnnotation
    @Provides
    @Singleton
    fun provideHttpRetrofit(@HttpClientAnnotation okHttpClient: OkHttpClient): Retrofit {
        return OkHttpClientManager.createRetrofit(okHttpClient)
    }

    /**
     * 提供HttpsRetrofit单例
     */
    @HttpsRetrofitAnnotation
    @Provides
    @Singleton
    fun provideHttpsRetrofit(@HttpsClientAnnotation okHttpsClient: OkHttpClient): Retrofit {
        return OkHttpClientManager.createRetrofit(okHttpsClient)
    }





}